package com.kingwood.algorithm.test;

import java.util.*;
import java.util.regex.Pattern;

public class ShenDuYouxianSousuo {

    static int m;
    static int n;
    static int k;

    static int ans = 0;

    static HashSet<Integer> visited = new HashSet<>();

    static int[][] offSets = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

    static int[] digitSums;

    /**
     * https://fcqian.blog.csdn.net/article/details/134674604
     * 小华地图寻宝
     * @param x
     * @param y
     */
    public static void dfs(int x, int y) {
        if (x < 0
                || x >= m
                || y <0
                || y >= n
                || visited.contains(x * n + y)
                || digitSums[x] + digitSums[y] > k) {
            return;
        }

        visited.add(x * n + y);
        ans++;

        for (int[] offset : offSets) {
            int newX = x + offset[0];
            int newY = y + offset[1];

            dfs(newX, newY);
        }
    }

    public static void digitSum(int maxSize) {
        digitSums = new int[maxSize];
        for (int i=0; i<maxSize; i++) {
            int num = i;
            while (num > 0) {
                digitSums[i] += num % 10;
                num = (num / 10);
            }
        }
    }

    /**
     * 解密犯罪时间
     * https://blog.csdn.net/qfc_128220/article/details/127634016
     * @param timeStr
     * @return
     */
    public static String getNextMinTime(String timeStr) {
        HashSet<Character> charSet = new HashSet<>();
        int len = timeStr.length();
        for (int i=0; i<len; i++) {
          Character c = timeStr.charAt(i);
          if (!c.equals(':')) {
              charSet.add(c);
          }
        }

        Character[] charArr = charSet.toArray(new Character[0]);
        LinkedList<Character> path = new LinkedList<>();
        ArrayList<String> res = new ArrayList<>();

        dfsTime(charArr, path, res);

        res.sort(String::compareTo);

        String ans = "";
        int curIndex = res.indexOf(timeStr.replace(":", ""));
        if (curIndex == res.size() - 1) {
            ans = res.get(0);
        } else {
            ans = res.get(curIndex + 1);
        }

        StringBuilder sb = new StringBuilder(ans);
        sb.insert(2, ':');
        return sb.toString();
    }

    public static String getNextMinTime2(String timeStr) {
        int len = timeStr.length();
        HashSet<Character> charSet = new HashSet<>();
        for (int i = 0; i < len; i++) {
            Character cur = timeStr.charAt(i);
            if (cur != ':') {
                charSet.add(cur);
            }
        }

        Character[] charArr = charSet.toArray(new Character[0]);
        LinkedList<Character> path = new LinkedList<>();
        ArrayList<String> res = new ArrayList<>();

        dfsTime2(charArr, path, res);

        res.sort(String::compareTo);

        int curIndex = res.indexOf(timeStr.replace(":", ""));
        String ans = "";
        if (curIndex == res.size() - 1) {
            ans = res.get(0);
        } else {
            ans = res.get(curIndex + 1);
        }

        StringBuilder tb = new StringBuilder(ans);
        tb.insert(2, ":");
        return tb.toString();
    }

    public static Pattern p = Pattern.compile("(([01][0-9])|([2][0-3]))[0-5][0-9]");
    public static Pattern p1 = Pattern.compile("(([01][0-9])|([2][0-3]))[0-5][0-9]");
    public static Pattern p2 = Pattern.compile("(([01][0-9])|([2][0-3]))[0-5][0-9]");
    public static void dfsTime(Character[] charArr, LinkedList<Character> path, ArrayList<String> res) {
        if (path.size() == 4) {
            StringBuilder sb = new StringBuilder();
            for (Character c : path) {
                sb.append(c);
            }
            String timeStr = sb.toString();

            if (p.matcher(timeStr).find()) {
                res.add(timeStr);
            }

            return;
        }

        for (Character c : charArr) {
            path.add(c);
            dfsTime(charArr, path, res);
            path.removeLast();
        }
    }

    public static void dfsTime2(Character[] charArr, LinkedList<Character> path, ArrayList<String> res) {
        if (path.size() == 4) {
            StringBuilder sb = new StringBuilder();
            for (Character c : path) {
                sb.append(c);
            }

            String timeStr = sb.toString();
            if (p.matcher(timeStr).find()) {
                res.add(timeStr);
            }

            return;
        }

        for (Character c : charArr) {
            path.add(c);
            dfsTime2(charArr, path, res);
            path.removeLast();
        }
    }

    public static int getArrayNums(int[] nums1, int[] nums2) {
        ArrayList<ArrayList<Integer>> res = new ArrayList<>();
        LinkedList<Integer> path = new LinkedList<>();

        dfsNumArr(nums1, path, res);

        int count = 0;
        int preAns = -1;
        int curAns = 0;

        int len = nums1.length;
        for (ArrayList<Integer> list : res) {
            curAns = 0;
//            System.out.println(list.toString());
            for (int i =0; i<len; i++) {
                if (list.get(i) > nums2[i]) {
                    curAns++;
                }
            }

            if (curAns > preAns) {
                preAns = curAns;
                count = 1;
            } else if (curAns == preAns){
                count++;
            } else {
                // nothing todo
            }
        }

        return count;
    }

    public static void dfsNumArr(int[] nums, LinkedList<Integer> path, ArrayList<ArrayList<Integer>> res) {
        if (path.size() == nums.length) {
            res.add(new ArrayList<>(path));
            return;
        }

        for (int m : nums) {
            if (path.contains(m)) {
                continue;
            }

            path.add(m);
            dfsNumArr(nums, path, res);
            path.removeLast();
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
//        m = scanner.nextInt();
//        n = scanner.nextInt();
//        k = scanner.nextInt();
//
//        digitSum(Math.max(m, n));
//        dfs(0, 0);
//        System.out.println(ans);

//        String timeStr = scanner.nextLine();
////        System.out.println(p.matcher(timeStr).find());
//        System.out.println(getNextMinTime(timeStr));

        int[] nums1 = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] nums2 = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int count = getArrayNums(nums1, nums2);
        System.out.println(count);

    }
}
